/*  ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
*   Copyright 2014 Jan-Marwin Wollschläger                                   *
*                                                                            *
*   Licensed under the Apache License, Version 2.0 (the "License");          *
*   you may not use this file except in compliance with the License.         *
*   You may obtain a copy of the License at                                  *
*                                                                            *
*       http://www.apache.org/licenses/LICENSE-2.0                           *
*                                                                            *
*   Unless required by applicable law or agreed to in writing, software      *
*   distributed under the License is distributed on an "AS IS" BASIS,        *
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
*   See the License for the specific language governing permissions and      *
*   limitations under the License.                                           *
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **   */   

class Line implements ILine
{
   private IVector2 firstPoint;
   private IVector2 secondPoint;
   	
   public Line(IVector2 fst, IVector2 scd)
   {
		firstPoint  = fst;
		secondPoint = scd;
   }
	
   /**
   * @return The first Point of this line.
   **/
   public IVector2 getFirstPoint()
   {
	   return firstPoint;
   }
  
   /**
   * @return The second Point of this line.
   **/
   public IVector2 getSecondPoint()
   {
	   return secondPoint;
   }
  
   /**
   * @return Returns secondPoint - firstPoint.
   **/
   public IVector2 getDirection()
   {
	   return secondPoint.vecMinus(firstPoint);
   }
  
   /**
   * @return Returns a vector that is orthogonal to the direction of
   * this instance.
   **/
   public IVector2 getOrthogonalDirection()
   {
	   return getDirection().getOrthogonal();
   }
  
   /**
   * @return The length of this line.
   **/
   public float getLen()
   {
	   return getDirection().getLen();
   }
   
   /**
   * @return The squared length of this line.
   **/
   public float getLenSquared()
   {
	   return getDirection().getLenSquared();
   }
   
   /**
    * Returns the by the specified amount shrinked line, so that the
    * shrink operation is performed equally on both sides of the line.
    *  
    * @param amount How much to shrink is line on both ends,
    * e.g. 0.5 will shrink
    * this line by 50%, while 1.0 would cancel this line out.
    *
    * @return  The ILine instance shrunken by the supplied amount.
    **/
   public ILine shrink(float amount)
   {
	   final IVector2 dirVec = getDirection();
	   final IVector2 p1	   = getFirstPoint();
	   final IVector2 p2	   = getSecondPoint();
	   return new Line(p1.vecPlus(dirVec.mult(amount/2.0f)),
						 p2.vecPlus(dirVec.mult(-amount/2.0f)));		
   }
  
}



